package day_2022_12_to_3.year2023;

/**
 * @author haomin
 * @date 2023/04/11 22:05
 **/
public class Day4_11_Num1041 {
    class Solution {
        public boolean isRobotBounded(String instructions) {
            int x = 0,y = 0;
            int flag = 0;
            for (int i = 0;i < 100;i++){
                for (char c : instructions.toCharArray()){
                    if (c == 'G'){
                        if (flag == 0){
                            y++;
                        } else if (flag == 1){
                            x++;
                        } else if (flag == 2){
                            y--;
                        } else {
                            x--;
                        }
                    } else if (c == 'L'){
                        flag = (flag + 3) % 4;
                    } else if (c == 'R'){
                        flag = (flag + 1) % 4;
                    }
                }
                if (x == 0 && y == 0){
                    return true;
                }
            }
            return false;
        }
    }
}